/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author jefoutta
 */
import java.util.*;

public class Memory {

    public static ArrayList<String> memory_segment = null;
    public static Integer ip = null;
    public static Hashtable<String,Integer> label_table = new Hashtable(); //esta es una hashtable que guardará la etiqueta (String) y el numero de linea que se encuentra (Integer)
    private static Hashtable<Integer, Integer> ip_stack = new Hashtable();
    public static Hashtable<Integer,ArrayList<String>> memory_stack = new Hashtable();
    private static Hashtable<Integer, Hashtable<String,Integer>> label_table_table = new Hashtable();

    public static void setMemory(ArrayList<String> array){
        memory_segment = null;
        memory_segment = array;
        ip = 0;
    }

    public static Integer getIP(){
        return ip;
    }

    public static void incIP(){
        ip++;
    }

    public static void setIP(Integer n){
        ip = n;
    }

    public static void pushMemory(Integer procid){
        memory_stack.put(procid, memory_segment);
        ip_stack.put(procid, new Integer(ip));
        label_table_table.put(procid, new Hashtable(label_table));
    }

    public static void popMemory(Integer procid){
        setMemory(memory_stack.get(procid));
        ip = ip_stack.get(procid);
        label_table = label_table_table.get(procid);
        memory_stack.remove(procid);
        ip_stack.remove(procid);
        label_table_table.remove(procid);
    }
}
